using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace Game1
{
    public enum MouseButton
    {
        MiddleButton,
        LeftButton,
        RightButton
    }

    public class Input
    {
        static KeyboardState currentState;
        static KeyboardState lastState;
        static MouseState curMouseState;
        static MouseState lastMouseState;
            
        public static void update()
        {
            lastState = currentState;
            currentState = Keyboard.GetState();

            lastMouseState = curMouseState;
            curMouseState = Mouse.GetState();
        }
        /// <summary>
        /// Return true while the key is pressed. For continuous
        /// action.
        /// </summary>
        public static bool IsKeyDown(Keys ks)
        {
            return currentState.IsKeyDown(ks);
        }
        /// <summary>
        /// Return true only when the key gets pressed. For single
        /// actions.
        /// </summary>
        public static bool IsKeyPressed(Keys ks)
        {
            return currentState.IsKeyDown(ks)&&!lastState.IsKeyDown(ks);
        }

        public static Vector2 getMouseTranslation()
        {
            Vector2 moved =  new Vector2(curMouseState.X - lastMouseState.X,
                                curMouseState.Y - lastMouseState.Y);
            
            Mouse.SetPosition(Base.Window.ClientBounds.Width / 2, Base.Window.ClientBounds.Height / 2);
            return moved;
        }

        public static Vector2 getMousePosition()
        {
            return new Vector2(curMouseState.X, curMouseState.Y);
        }

        public static bool isMouseClicked( MouseButton mb)
        {
            if ((curMouseState.RightButton == ButtonState.Pressed) && (mb == MouseButton.RightButton)) return true;
            if ((curMouseState.LeftButton == ButtonState.Pressed) && (mb == MouseButton.LeftButton)) return true;
            if ((curMouseState.MiddleButton == ButtonState.Pressed) && (mb == MouseButton.MiddleButton)) return true;
            return false;
        }
    }
}
